<template>
  <div class="empty">

  </div>
</template>
<script>
import { Button } from 'vant'
export default {
  components: {
    [Button.name]: Button
  },
  name: 'BootPage',
  props: {
    top: {
      type: [String, Number],
      required: true,
      default: 50
    }
  },

  data () {
    return {
      showToast: false, // 用来控制toast是否显示
      toastContent: '', // toast中显示的内容
      num: 0 // 这个是用来计数，防止用户连续点击出现setTimeout重复调用导致用户体验差
    }
  },

  computed: {
    show () {
      return this.value
    }
  },
  render: createElement => {
    return createElement('div', {
      class: {
        'my-toast': this.showToast
      },
      attrs: {
        style: 'top:' + this.top // 这里是获取父组件传过来的top值默认定义的是50在中间，
      },
      domProps: {
        innerHTML: this.toastContent // 这一步的作用是解析传过来的toast内容中的字符串中的HTML标签主要是解析换行标签
      }
    })
  },

  methods: {
    // 轻提示函数，value传入提示文字，time显示时间
    toastShow (value, time) {
      this.num = this.num + 1 // 计次的num+1防止连点
      if (this.num < 2) {
        this.showToast = true // toast显示
        this.toastContent = value // toast中内容进行赋值
        setTimeout(() => {
          this.showToast = false
          this.num = 0
        }, time)
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.my-toast {
  white-space: nowrap;
  position: fixed;
  top: 50%;
  left: 50%;
  display: flex;
  color: #fff;
  font-size: 14px;
  line-height: 20px;
  border-radius: 4px;
  align-items: center;
  flex-direction: column;
  box-sizing: border-box;
  -webkit-transform: translate3d(-50%, -50%, 0);
  background-color: rgba(0, 0, 0, 0.7);
  padding: 0.1rem 0.2rem;
  z-index: 999;
  text-align: center;
}

.square-block {
  margin: 15% auto 0;
  border: 1px solid transparent;
  width: 40%;
  position: relative;

  &-dummy {
    margin-top: 100%;
  }

  &-box {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    -moz-box-align: center;
    -moz-box-pack: justify;
    align-items: center;
    align-content: space-around;
    box-sizing: border-box;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    justify-content: center;
    overflow: hidden;
    width: 100%;
    flex-wrap: nowrap;

    img {
      width: 100%;
      height: auto;
    }
  }

  &-dot {
    position: absolute;
    right: -8px;
    bottom: 8px;
    width: 8px;
    height: 16px;
    background: #0193cc;
  }
}

.empty {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  left: 0;
  top: 0;
  background: #f8f8f8;

  &-content {
    padding: 15px;
    text-align: center;
    font-weight: normal;
    &__title {
      font-size: 16px;
    }
    &__subtitle {
      font-size: 12px;
      color: #ccc;
      text-transform: uppercase;
      font-weight: 300;
      margin: 0;
    }
    &__message {
      padding: 5px 15px;
      color: #aaa;
      font-size: 12px;
      font-weight: 300;
      margin-top: 10px;
    }
  }

  &-button {
    padding: 10px 0;
    text-align: center;
    margin-top: 20px;
    .van-button {
      padding: 0 20px;
      height: 38px;
      line-height: 38px;
    }
  }
}
</style>
